package mybatis.web;

import mybatis.pojo.Page;
import mybatis.pojo.Subject;
import mybatis.services.SubjectService;
import mybatis.util.StrUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 汤舒青
 * @Version 1.0
 */

@WebServlet("/subject")
public class SubjectServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        this.doGet(req,resp);
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String subname = req.getParameter("subName");
        subname = subname == null ? "" : subname;
        int pageNo = StrUtil.toInt(req.getParameter("pageNo"), 1);
        req.setAttribute("pageNo",pageNo);
        req.setAttribute("subName",subname);
        Page<Subject> paging = SubjectService.ME.paging(pageNo, subname);
        req.setAttribute("paging",paging);
        req.getRequestDispatcher("/WEB-INF/jsp/subjectServlet.jsp").forward(req,resp);
    }
}
